package com.smile.weather.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.smile.weather.R;
import com.smile.weather.bean.HourWeatherData;

import java.util.List;

/**
 * Created by smile on 2016/8/23.
 */
public class RecyclerAdapter_Hour extends RecyclerView.Adapter<RecyclerAdapter_Hour.ViewHolder> {
    private List<HourWeatherData> mDatas;
    private Context mContext;

    public RecyclerAdapter_Hour(Context context, List<HourWeatherData> mDatas) {
        this.mDatas = mDatas;
        this.mContext = context;
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = View.inflate(parent.getContext(), R.layout.item_hour, null);
        ViewHolder holder = new ViewHolder(view);

        return holder;
    }

    @Override
    public void onBindViewHolder(ViewHolder holder, int position) {
        HourWeatherData data = mDatas.get(position);
        holder.tv_hour.setText(data.getHour());
        holder.iv_weather.setImageResource(mContext.getResources().getIdentifier(data.getWeather_icon(), "drawable",
                "com.smile.weather"));
        holder.tv_weather.setText(data.getWeather());
        holder.tv_temperature.setText(data.getTemperature());
    }

    @Override
    public int getItemCount() {
        return mDatas.size();
    }

    public static class ViewHolder extends RecyclerView.ViewHolder {

        public TextView tv_hour;
        public ImageView iv_weather;
        public TextView tv_weather;
        public TextView tv_temperature;

        /**
         * @Description: TODO
         * @param itemView
         */
        public ViewHolder(View itemView) {
            super(itemView);
            tv_hour = (TextView) itemView.findViewById(R.id.tv_hour);
            iv_weather = (ImageView) itemView.findViewById(R.id.iv_weather);
            tv_weather = (TextView) itemView.findViewById(R.id.tv_weather);
            tv_temperature = (TextView) itemView.findViewById(R.id.tv_temperature);
        }
    }

}
